﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using TinyCinema.Data;
using System.Windows.Input;
using System.Windows.Controls;
using System.Collections.ObjectModel;

namespace Reports.Promotion
{
    public class Report1 : DependencyObject
    {
        public static DependencyProperty PromotionProperty = DependencyProperty.Register("Promotion", typeof(TinyCinema.Data.Promotion), typeof(Report1));
        public TinyCinema.Data.Promotion Promotion
        {
            get { return (TinyCinema.Data.Promotion)GetValue(PromotionProperty); }
            set
            {
                SetValue(PromotionProperty, value);
            }
        }
        public static DependencyProperty lstPromotionProperty = DependencyProperty.Register("lstPromotion", typeof(ObservableCollection<TinyCinema.Data.Promotion>), typeof(Report1));
        public ObservableCollection<TinyCinema.Data.Promotion> lstPromotion
        {
            get { return (ObservableCollection<TinyCinema.Data.Promotion>)GetValue(lstPromotionProperty); }
            set { SetValue(lstPromotionProperty, value); }
        }
        public Report1()
        {
            lstPromotion = TinyCinema.Data.Promotion.GetAllPromotion();
        }
        public CrystalReport1 Load(TinyCinema.Bussiness.Login.Employee LoginInfo)
        {
            string sql;
            CrystalReport1 report = new CrystalReport1();
            if (Promotion == null)
            {
                sql = "select Phim.TenPhim,SUATCHIEU.NgayChieu,Count(VE.MaVe) as SoLuong,Sum(VE.Gia) as TongDoanhSo"
                    + " from VE,SUATCHIEU,PHIM"
                    + " where PHIM.MaPhim=SUATCHIEU.MaPhim"
                    + " and VE.MaSC=SUATCHIEU.MaSC"
                    + " and SUATCHIEU.NgayChieu>='" + lstPromotion[0].StartDate + "'"
                    + " and SUATCHIEU.NgayChieu<='" + lstPromotion[0].EndDate + "'"
                    + " group by PHIM.TenPhim,SUATCHIEU.NgayChieu";
                report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
                report.SetParameterValue("Promotion", lstPromotion[0].Name.ToUpper());
                report.SetParameterValue("StartDate", lstPromotion[0].StartDate);
                report.SetParameterValue("EndDate", lstPromotion[0].EndDate);
            }
            else
            {
                sql = "select Phim.TenPhim,SUATCHIEU.NgayChieu,Count(VE.MaVe) as SoLuong,Sum(VE.Gia) as TongDoanhSo"
                + " from VE,SUATCHIEU,PHIM"
                + " where PHIM.MaPhim=SUATCHIEU.MaPhim"
                + " and VE.MaSC=SUATCHIEU.MaSC"
                + " and SUATCHIEU.NgayChieu>='" + Promotion.StartDate + "'"
                + " and SUATCHIEU.NgayChieu<='" + Promotion.EndDate + "'"
                + " group by PHIM.TenPhim,SUATCHIEU.NgayChieu";
                report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
                report.SetParameterValue("Promotion", Promotion.Name.ToUpper());
                report.SetParameterValue("StartDate", Promotion.StartDate);
                report.SetParameterValue("EndDate", Promotion.EndDate);
            }
            report.SetParameterValue("EmployeeName", LoginInfo.Emp.Name);
            return report;
        }
    }
}
